package com.example.mp.entity;

import java.time.LocalDateTime;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.Version;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;

/**
 * @Author: LiYuhang
 * @Date: 2021/11/4 17:21
 * @Description: 基础字段
 */
@Getter
@Setter
public class BaseEntity {

    public static final String GMT_CREATE = "gmtCreate";
    public static final String GMT_MODIFIED = "gmtModified";
    public static final String CREATOR = "creator";
    public static final String EDITOR = "editor";
    public static final String VERSION = "version";

    public static final String FIELD_ID = "id";
    public static final String FIELD_VALID = "disabled";
    public static final String FIELD_GMT_CREATE = "gmt_create";
    public static final String FIELD_GMT_MODIFIED = "gmt_modified";
    public static final String FIELD_CREATOR = "creator";
    public static final String FIELD_EDITOR = "editor";
    public static final String FIELD_VERSION = "version";
    private static final long serialVersionUID = -4961668970285530836L;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime gmtCreate;

    /**
     * 修改时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime gmtModified;

    /**
     * 创建人
     */
    @TableField(fill = FieldFill.INSERT)
    private String creator;

    /**
     * 修改人
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private String editor;

    /**
     * 是否有效（0：有效；1：无效）
     */
    @TableLogic(value = "0", delval = "1")
    private Integer disabled;

    /**
     * 版本号
     */
    @Version
    @TableField(fill = FieldFill.INSERT_UPDATE, update = "%s+1")
    private Integer version;
}
